package evolution.problem;

import static java.lang.Math.cos;

public class ShubertMinimization extends AbstractMinimizationProblem {

	public static final ProblemConstraints CONSTRAINTS = new ProblemConstraints(
			2, -10, 10);

	public ShubertMinimization() {
		super(CONSTRAINTS);
	}

	/**
	 * <a
	 * href>http://www.staff.brad.ac.uk/jpli/research/scga/shubert/index.htm#n
	 * <a/>
	 */
	@Override
	public double getValue(double[] x) {
		double n = x.length;
		double product = 1;

		for (int i = 0; i < n; i++) {
			double sum = 0;
			for (int j = 1; j <= 5; j++) {
				double val = j * cos((j + 1) * x[i] + j);
				sum += val;
			}
			product *= sum;
		}
		return product;
	}

	@Override
	public String getGnuplotFunction() {
		return "(cos(2*x+1) + 2*cos(3*x+2) + 3*cos(4*x+3) + 4*cos(5*x+4) + 5*cos(6*x+5)) * (cos(2*y+1) + 2*cos(3*y+2) + 3*cos(4*y+3) + 4*cos(5*y+4) + 5*cos(6*y+5))";
	}

	@Override
	public String getGnuplotFunctionName() {
		return "shubert";
	}

	@Override
	public double getOptimumValue() {
		return Integer.MIN_VALUE;
	}

	@Override
	public boolean isOptimumValueKnown() {
		return false;
	}
}
